home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / fractals / apfelkiste / apfelkiste2.0 / source / apfelkiste2.0src.lzh / Fixpoint000.a < prev    next >
Text File  |  1991-07-21  |  4KB  |  211 lines

  1. ** This is the *BIG* one. Here lies 80% of the work I put into
  2. ** "Apfelkiste". Basically this function  does the same as it's
  3. ** float counterpart Iter_FLOAT() in Float.c, but it uses a
  4. ** fix-point format for real calculations.
  5. ** Refer to the revision header of "Apfelkiste.c" for the exact
  6. ** definition.
  7. ** The conversion of normal floats to my format is quite easy:
  8. **    Multiply the float by 2**24 (doing a 24 bit shift in fact),
  9. **    cast to long and there you are...
  10. **
  11. ** This file needs to be assembled separately in order to recompile 
  12. ** the whole source. I really think Lattice DOES need an inline
  13. ** assembly facility, or at least the workbench interface should
  14. ** update and link *.a files the same way it does with *.c and *.o .
  15.  
  16.     CSECT    DATA,1,,2,2
  17.  
  18.     XREF    _maxcol
  19.     XREF    _MAXITER
  20.  
  21.     CSECT    TEXT,0,,1,2
  22.  
  23.     XDEF    _Iter_FXP
  24.  
  25. _Iter_FXP:
  26.     movem.l    D3-D7,-(SP)
  27.  
  28.     move.l    D1,D3        ;(r)
  29.     move.l    D2,D4        ;(i)
  30.     move.w    _MAXITER(A4),D0
  31.     ext.l    D0        ;(count)     
  32.  
  33. __while:
  34.     swap    D0
  35.     move.l    D3,A1        ;save r
  36.     tst.l    D3        ;r < 0?
  37.     bpl.s    __skip1        ;no
  38.     neg.l    D3        ;yes, negate
  39.  
  40. __skip1:
  41.     move.w    D3,D5        ;rl * rl -> D5
  42.     mulu.w    D3,D5
  43.     clr.w    D5        ;24 bit right shift
  44.     swap    D5
  45.     lsr.w    #8,D5
  46.  
  47.     move.l    D3,D6        ;2 * rl * rh -> D6
  48.     swap    D6
  49.     mulu.w    D3,D6
  50.     lsr.l    #7,D6        ;7 bit only, because of factor 2!
  51.     add.l    D6,D5        ;collect in D5
  52.  
  53.     swap    D3        ;rh * rh -> D3
  54.     mulu.w    D3,D3
  55.     asl.l    #8,D3        ;8 bit left shift
  56.     add.l    D3,D5        ;collect in D5
  57.  
  58.     move.l    A1,D3        ;fetch r back
  59.  
  60.     move.l    D4,A0        ;save i
  61.     tst.l    D4        ;D4 < 0?
  62.     bpl.s    __skip2        ;no
  63.     neg.l    D4        ;yes, negate
  64.  
  65. __skip2:
  66.     move.w    D4,D6        ;il * il -> D6
  67.     mulu.w    D4,D6
  68.     clr.w    D6        ;24 bit right shift
  69.     swap    D6
  70.     lsr.w    #8,D6
  71.     add.l    D6,D5        ;collect in D5
  72.  
  73.     move.l    D4,D6        ;2 * il * ih -> D6
  74.     swap    D6
  75.     mulu.w    D4,D6
  76.     lsr.l    #7,D6        ;7 bit only because of factor 2!
  77.     add.l    D6,D5        ;collect in  D5
  78.  
  79.     swap    D4        ;ih * ih -> D4
  80.     mulu.w    D4,D4
  81.     asl.l    #8,D4
  82.     add.l    D4,D5        ;collect in D5
  83.  
  84. ;now D5 contains r * r + i * i
  85.  
  86.     cmp.l    A2,D5        ;test for upper bound
  87.     bge    __done        ;exceeded => end
  88.  
  89. ;evaluate ( r + i ) * ( r - i ) + p -> D7
  90.  
  91.     ;No need to save r and i (D3 / D4), beacause they're already
  92.     ;in A1 / A0 (well, saved another 4 machine cycles!)
  93.     
  94.     add.l    A0,D3        ;r+i -> D3
  95.     move.l    A1,D4        ;r-i -> D4
  96.     sub.l    A0,D4
  97.  
  98.     tst.l    D3        ;r < 0?
  99.     bpl.s    __skip3        ;no
  100.     neg.l    D3        ;yes, negate
  101.     not.w    D0        ;remember negative sign
  102.  
  103. __skip3:
  104.     tst.l    D4        ;i < 0?
  105.     bpl.s    __skip4        ;no
  106.     neg.l    D4        ;yes, negate
  107.     not.w    D0        ;remember negative sign
  108.  
  109. __skip4:
  110.     move.w    D3,D7        ;rl * il -> D7
  111.     mulu.w    D4,D7
  112.     clr.w    D7        ;24 bit shift
  113.     swap    D7
  114.     lsr.w    #8,D7
  115.  
  116.     swap    D4        ;rl * ih -> D6
  117.     move.w    D4,D6
  118.     mulu.w    D3,D6
  119.     lsr.l    #8,D6        ;8 bit shift
  120.     
  121.     add.l    D6,D7        ;collect in D7
  122.  
  123.     swap    D3        ;rh * ih -> D6
  124.     move.w    D4,D6
  125.     mulu.w    D3,D6
  126.     asl.l    #8,D6        ;8 bit shift
  127.     add.l    D6,D7        ;collect in D7
  128.  
  129.     swap    D4        ;rh * il -> D6
  130.     mulu.w    D3,D4
  131.     lsr.l    #8,D4        ;8 bit shift
  132.     add.l    D4,D7        ;collect in D7
  133.  
  134.     tst.w    D0        ;correct result?
  135.     beq.s    __skip5        ;no
  136.     neg.l    D7        ;yes
  137.     clr.w    D0        ;erase marker
  138.  
  139. __skip5:
  140.     add.l    D1,D7        ;add p
  141.  
  142. ;evaluate 2 * r * i + q -> D5
  143.  
  144.     move.l    A1,D3        ;call r and i back
  145.     move.l    A0,D4
  146.     
  147.     tst.l    D3        ;r < 0?
  148.     bpl.s    __skip6        ;no
  149.     neg.l    D3        ;yes, negate
  150.     not.w    D0        ;remember negative sign
  151.  
  152. __skip6:
  153.     tst.l    D4        ;i < 0?
  154.     bpl.s    __skip7        ;no
  155.     neg.l    D4        ;yes, negate
  156.     not.w    D0        ;remember negative sign
  157.  
  158. __skip7:
  159.     move.w    D3,D5        ;2 * rl * il -> D5
  160.     mulu.w    D4,D5
  161.     clr.w    D5        ;23 bit shift (instead of 24, because of factor 2)
  162.     swap    D5
  163.     lsr.w    #7,D5
  164.  
  165.     swap    D4        ;2 * rl * ih -> D6
  166.     move.w    D4,D6
  167.     mulu.w    D3,D6
  168.     lsr.l    #7,D6        ;7 bit shift (instead of 8, because of factor 2)
  169.     add.l    D6,D5        ;collect in D5
  170.  
  171.     swap    D3        ;2 * rh * ih -> D6
  172.     move.w    D4,D6
  173.     mulu.w    D3,D6
  174.     asl.l    #8,D6        ;9 bit shift  (instead of 8, because of factor 2)
  175.     add.l    D6,D6        ;add.l is 2 cycles faster as asl.l #1  !
  176.     add.l    D6,D5        ;collect in D5
  177.  
  178.     swap    D4        ;2 * rh * il -> D6
  179.     mulu.w    D3,D4
  180.     lsr.l    #7,D4        ;7 bit shift (instead of 8, because of factor 2)
  181.     add.l    D5,D4        ;collect in D4, i = 2 * r * i
  182.  
  183.     tst.w    D0        ;correct result?
  184.     beq.s    __skip8        ;no
  185.     neg.l    D4        ;yes
  186.     clr.w    D0        ;erase marker
  187.  
  188. __skip8:
  189.     add.l    D2,D4        ;add q, i = 2 * r * i + q
  190.  
  191.     move.l    D7,D3        ;r = ( r + i ) * ( r - i ) + p
  192.  
  193.     swap    D0
  194.     dbra    D0,__while    ;to start of loop
  195.  
  196.     moveq    #0,D0        ;return 0, if MAXITER was exceeded
  197.  
  198.     movem.l    (SP)+,D3-D7
  199.     rts
  200.  
  201. __done:
  202.     swap    D0
  203.     divu.w    _maxcol(A4),D0    ;return ( count % maxcol )
  204.     clr.w    D0
  205.     swap    D0
  206.  
  207.     movem.l    (SP)+,D3-D7
  208.     rts
  209.  
  210.     END
  211.